<?php
require_once 'kernel/form.php';

General::getTpl()->assign('extraTitle',"Allgemeine Einstellungen");
if(Admin::checkPermission('canEditSettings')) {
	// Form-Data
	$formField = array();
	$i = 0;
	$formField[$i]['fieldName'] = "Seitenname";
	$formField[$i]['fieldDescription'] = "Der Name der Seite.";
	$formField[$i]['fieldType'] = Form::$TYPE_TEXT;
	$formField[$i]['fieldDefaultValue'] = Settings::getInstance()->getSetting("general.pageTitle");
	$formField[$i]['fieldCheck'] = true;
	$formField[$i]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
	$i++;
	
	$formField[$i]['fieldName'] = "Slogan";
	$formField[$i]['fieldDescription'] = "Der Slogan der Seite.";
	$formField[$i]['fieldType'] = Form::$TYPE_TEXT;
	$formField[$i]['fieldDefaultValue'] = Settings::getInstance()->getSetting("general.pageSlogan");
	$formField[$i]['fieldCheck'] = true;
	$formField[$i]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
	$i++;	
	
	$formField[$i]['fieldName'] = "Seite online?";
	$formField[$i]['fieldDescription'] = "Ist die Seite z.Zt. online?";
	$formField[$i]['formName'] = "pageOnline";
	$formField[$i]['fieldType'] = Form::$TYPE_SELECT;
	$formField[$i]['fieldDefaultValue'] = (Settings::getInstance()->getSetting("general.pageOnline") == 0) ? "Ja":"Nein";
	$formField[$i]['fieldCheck'] = false;
	$formField[$i]['fieldSelectOptions'] = "Ja::--::Nein";
	$formField[$i]['fieldSelectMultiple'] = false;
	$i++;
	
	
	$formField[$i]['fieldName'] = "Offline-Erkl&auml;rung (max. 255 Zeichen)";
	$formField[$i]['formName'] = "offlineExplanation";
	$formField[$i]['fieldDescription'] = "Die Erkl&auml;rung warum die Seite offline ist.";
	$formField[$i]['fieldSelectOptions'] = "30_5";
	$formField[$i]['fieldType'] = Form::$TYPE_TEXTAREA;
	$formField[$i]['fieldDefaultValue'] = Settings::getInstance()->getSetting("general.offlineExplanation");
	$formField[$i]['fieldCheck'] = false;
	$i++;
	
	$formField[$i]['fieldName'] = "Footer";
	$formField[$i]['fieldDescription'] = "Der Text wird am Ende der Seite angezeigt.";
	$formField[$i]['fieldType'] = Form::$TYPE_TEXT;
	$formField[$i]['fieldDefaultValue'] = Settings::getInstance()->getSetting("general.footerText");
	$formField[$i]['fieldCheck'] = false;
	$i++;
	
	
	$formField[$i]['fieldName'] = "Mod-Rewrite benutzen?";
	$formField[$i]['fieldDescription'] = "Wenn Mod-Rewrite an ist, werden Suchmaschinenfreundliche URL's verwendet.";
	$formField[$i]['formName'] = "modRewrite";
	$formField[$i]['fieldType'] = Form::$TYPE_SELECT;
	$formField[$i]['fieldDefaultValue'] = (Settings::getInstance()->getSetting("general.useModRewrite") == 0) ? "Ja":"Nein";
	$formField[$i]['fieldCheck'] = false;
	$formField[$i]['fieldSelectOptions'] = "Ja::--::Nein";
	$formField[$i]['fieldSelectMultiple'] = false;
	$i++;
	
	$formField[$i]['fieldName'] = "Dauer der IP-Sperre";
	$formField[$i]['formName'] = "ipLockLength";
	$formField[$i]['fieldDescription'] = "Wie lange muss der User warten, bis er ein Formular wieder abschicken darf?";
	$formField[$i]['fieldType'] = Form::$TYPE_TEXT;
	$formField[$i]['fieldDefaultValue'] = Settings::getInstance()->getSetting("general.ipLockLength");
	$formField[$i]['fieldCheck'] = true;
	$formField[$i]['fieldCheckExtra'] = Form::$CHECK_TEXT_NUMERIC;
	$i++;
	    	
	$form = new Form();
	$form->initByData("Allgemeine Einstellungen",true,"Speichern!",$formField);
	
	// Done?
	if($form->completeCheck()) {
		Settings::getInstance()->changeSetting("general.pageTitle",$_POST['Seitenname']);
		Settings::getInstance()->changeSetting("general.pageSlogan",$_POST['Slogan']);
		Settings::getInstance()->changeSetting("general.footerText",$_POST['Footer']);
		$useModRewrite = ($_POST['modRewrite'][0] == "Ja") ? 0:1;
		Settings::getInstance()->changeSetting("general.useModRewrite",$useModRewrite);
		$pageOnline = ($_POST['pageOnline'][0] == "Ja") ? 0:1;
		Settings::getInstance()->changeSetting("general.pageOnline",$pageOnline);
		Settings::getInstance()->changeSetting("general.offlineExplanation",$_POST['offlineExplanation']);
		Settings::getInstance()->changeSetting("general.ipLockLength",$_POST['ipLockLength']);
		
		
		// Save Data
		General::ouputMessage('Erfolgreich','Die Einstellungen wurden erfolgreich gespeichert.');
	}else{
		$form->outputFormular('body','formular.html');
	}
}else{
	General::ouputMessage('Fehler','Sie haben nicht gen&uuml;gend Rechte um diese Seite zu betrachten');
}
?>